package com.oig.sys.workflow.dto;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.oig.common.validator.GroupAdd;
import com.oig.common.validator.GroupEdit;

import io.swagger.v3.oas.annotations.Hidden;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import org.springframework.format.annotation.DateTimeFormat;

import javax.validation.Valid;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import java.util.Date;
import java.util.List;

@Schema
@Data
public class AutoRuleDto {

	@Schema(description = "id", requiredMode = Schema.RequiredMode.NOT_REQUIRED)
	@NotNull(message = "参数错误,规则id不能为空", groups= {GroupEdit.class})
	private Integer id;

	@Schema(description = "规则名", requiredMode = Schema.RequiredMode.NOT_REQUIRED)
	@NotEmpty(message = "参数错误,规则名不能为空", groups= {GroupAdd.class, GroupEdit.class})
	private String autoRuleName;

	@Schema(description = "监听对象id,从选择的对象中带过来", requiredMode = Schema.RequiredMode.NOT_REQUIRED)
	@NotNull(message = "参数错误,监听对象id不能为空", groups= {GroupAdd.class, GroupEdit.class})
	private Integer listenerObjectId;
	@Schema(description = "监听对象名称,从选择的对象中带过来", requiredMode = Schema.RequiredMode.NOT_REQUIRED)
	@NotEmpty(message = "参数错误,监听对象名称不能为空", groups= {GroupAdd.class, GroupEdit.class})
	private String listenerObjectName;
    @Schema(description = "监听业务单据类型,从选择的对象中带过来", requiredMode = Schema.RequiredMode.NOT_REQUIRED)
    @NotEmpty(message = "参数错误,监听业务单据类型不能为空", groups= {GroupAdd.class, GroupEdit.class})
    private String relationType;


	@Schema(description = "监听事件id,从选择的事件中带过来", requiredMode = Schema.RequiredMode.NOT_REQUIRED)
	@NotNull(message = "参数错误,监听事件id不能为空", groups= {GroupAdd.class, GroupEdit.class})
	private Integer listenerEventId;
	@Schema(description = "监听事件名称,从选择的事件中带过来", requiredMode = Schema.RequiredMode.NOT_REQUIRED)
	@NotEmpty(message = "参数错误,监听事件名称不能为空", groups= {GroupAdd.class, GroupEdit.class})
	private String listenerEventName;
	@Schema(description = "监听对象对应数据库表名,从选择的事件中带过来", requiredMode = Schema.RequiredMode.NOT_REQUIRED)
	@NotEmpty(message = "参数错误,监听对象对应数据库表名不能为空", groups= {GroupAdd.class, GroupEdit.class})
	private String listenerTableName;
	@Schema(description = "监听事件,从选择的事件中带过来 delete,update,insert事件", requiredMode = Schema.RequiredMode.NOT_REQUIRED)
	@NotEmpty(message = "参数错误,监听事件不能为空", groups= {GroupAdd.class, GroupEdit.class})
	private String listenerEventOperation;
	@Schema(description = "监听业务单据单号属性名,从选择的事件中带过来", requiredMode = Schema.RequiredMode.NOT_REQUIRED)
	@NotEmpty(message = "参数错误,监听业务单据单号属性名不能为空", groups= {GroupAdd.class, GroupEdit.class})
	private String relationIdColumn;
	@Schema(description = "update事件条件配置,配置变更字段 {\"field\":\"\",\"listenerType\":\"\",\"oldValue\":\"\"\":\"\",\"newValue\":\"\",\"stepValue\":\"\"} listenerType 0-字段值发生任意变化 1-字段值变更为指定值 2-指定特定变更 3-变更大于指定步长 4-从无变有 5-从有变无")
	private String listenerUpdateCfg ;
	@Schema(description = "是否启用,0-未启用 1-启用")
	private String enable;

	@Hidden
	@Schema(description = "创建人id")
	private Integer createUserId;
	@Hidden
	@Schema(description = "创建人")
	private String createUserName;
	@Hidden
	@Schema(description = "创建时间")
	@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
	@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
	private Date createTime;
	@Hidden
	@Schema(description = "最后更新人id")
	private Integer lastUpdateId;
	@Hidden
	@Schema(description = "最后更新人")
	private String lastUpdateName;
	@Hidden
	@Schema(description = "最后更新时间")
	@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
	@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
	private Date lastUpdateTime;
	@Hidden
	@Schema(description = "所属租户id")
	private Integer tenantId;
	@Schema(description = "所属租户名称")
	private String tenantName;

	@Schema(description = "对应分支操作", requiredMode = Schema.RequiredMode.NOT_REQUIRED)
	@NotNull(message = "对应分支操作必填", groups={GroupAdd.class, GroupEdit.class})
	@Size(min = 1,message = "至少一个对应分支操作", groups={GroupAdd.class, GroupEdit.class})
	@Valid
	private List<AutoOperationDto> autoOperationDtoList;


}
